
// export function refreshRem() {
//     let width = document.documentElement.getBoundingClientRect().width;
//     const maxWidth = 750;
//     width > maxWidth && (width = maxWidth);
//     const rem =(width * 10)/750;
//     document.documentElement.style.fontSize = rem+'px'
// }
declare global {
  interface Window {
    sedLastPoint: any
    webkit: any
    Android: any
    WebViewJavascriptBridge: any
    android_download_right_is_true: any
  }
}
//data:{type:AIVipPage'}
export const flutterSendData = function (param: { type: string }) {
  const data=JSON.stringify(param)
  try {
    if (/(iPhone|iPad|iPod|iOS|Macintosh)/i.test(navigator.userAgent)) {
      window.webkit.messageHandlers.Native.postMessage(data);
    } else {
      if (window.Android && window.Android.getPostMessage) {
        window.Android.getPostMessage(data);
      }
      if (window.WebViewJavascriptBridge && window.WebViewJavascriptBridge.callHandler) {//新的与安卓交互方式
        window.WebViewJavascriptBridge.callHandler(
          'h5SendData'
          , data
          , function (responseData: any) {
            console.log(responseData)
          }
        );
      }
    }
  } catch (e) { }

};


export function refreshRem() {
  (function (designWidth, maxWidth) {
    var doc = document,
      win = window,
      docEl = doc.documentElement,
      remStyle = document.createElement('style'),
      tid: number;

    function adapt() {
      var d = window.document.createElement('div');
      d.style.width = '1rem';
      d.style.display = 'none';
      var head = window.document.getElementsByTagName('head')[0];
      head.appendChild(d);
      var defaultFontSize = parseFloat(window.getComputedStyle(d, null).getPropertyValue('width'));
      return defaultFontSize;
    }

    function refreshRem() {
      var width = docEl.getBoundingClientRect().width;
      maxWidth = maxWidth || 540;
      width > maxWidth && (width = maxWidth);
      var rem = ((width * 100) / designWidth) * (10 / adapt());
      remStyle.innerHTML = 'html{font-size:' + rem + 'px;}';
    }

    if (docEl.firstElementChild) {
      docEl.firstElementChild.appendChild(remStyle);
    } else {
      var wrap: HTMLDivElement | null = doc.createElement('div');
      wrap.appendChild(remStyle);
      doc.write(wrap.innerHTML);
      wrap = null;
    }
    //要等 wiewport 设置好后才能执行 refreshRem，不然 refreshRem 会执行2次；
    refreshRem();

    //   win.addEventListener(
    //     'resize',
    //     function() {
    //       clearTimeout(tid); //防止执行两次
    //       tid = setTimeout(refreshRem, 300);
    //     },
    //     false
    //   );

    win.addEventListener(
      'pageshow',
      function (e) {
        if (e.persisted) {
          // 浏览器后退的时候重新计算
          clearTimeout(tid);
          tid = window.setTimeout(refreshRem, 300);
        }
      },
      false
    );

    if (doc.readyState === 'complete') {
      doc.body.style.fontSize = '10px';
    } else {
      doc.addEventListener(
        'DOMContentLoaded',
        function (e) {
          doc.body.style.fontSize = '10px';
        },
        false
      );
    }
  })(750, 750);
}
export default function Text() { return 123 }